<style>
    .order-header-first {
        font-size: small;color: grey;
    }
    .order-header {
        font-size: small;color: grey;padding-left: 5%
    }
    .order-header-text {
        padding-left: 5px
    }
    .order-header-div {
        width: 15%;
        float: left;
    }
</style>

<?php
//发货方式
$deliveryOne = 1; //fba
$deliveryTwo = 2;   //海外
$deliveryThree = 3; //国内
?>

@foreach($paginator as $row)

    <?php $areaName = $row->area->area ?? ''; //站点名称 ?>

    <div id="order_{{ $row->order_no }}" class="box box-primary">
        <div class="box-header with-border" style="background-color: #f1f9fd">
            <div class="order-header-div">
                <span class="order-header-first">订单号: </span><a target="_blank" href="/xqc/customer-delivery/customer-order-detail?no8={{ $row->order_no ?? '' }}"><span class="order-header-text">{{ $row->order_no }}</span> <i class="fa fa-search" style="font-size: small;"></i></a>
            </div>
            <div class="order-header-div">
                <span class="order-header">收货国家: </span><span class="order-header-text">{{ $row->receiver->country }}</span>
            </div>
            <div class="order-header-div">
                <span class="order-header">发货站点: </span><span class="order-header-text">{{ $areaName }}</span>
            </div>
            <div class="order-header-div">
                <span class="order-header">订单平台: </span><span class="order-header-text">{{ \App\Models\Basics\SysPlat::getSysPlatTitle($row->plat_id) }}</span>
            </div>
            <div class="order-header-div">
                <span class="order-header">下单时间: </span><span class="order-header-text">{{ $row->order_at }}</span>
            </div>
            <div class="order-header-div">
                <span class="order-header">客户备注: </span><span class="order-header-text">{{ $row->order_remarks ?? '' }}</span>
            </div>
            <div class="box-tools pull-right">
                <button class="btn btn-box-tool list-detail-modal" title="添加产品" data-id="{{ $row->id }}" data-action="addListOutOrderSku">添加SKU产品</button>
                <button class="btn btn-box-tool list-modal" title="查看收货信息" data-id="{{ $row->id }}" data-action="viewDetail">查看收货人信息</button>
            </div>
        </div>

        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th style="width: 5%;"></th>
                    <th style="width: 10%;">SKU</th>
                    <th style="width: 25%;">产品名称</th>
                    <th style="width: 10%;">下单数量</th>
                    <th style="width: 10%;">已申发数量</th>
                    <th style="width: 10%;">状态</th>
                    <th style="max-width: 200px;">备注</th>
                    <th style="width: 10%;">操作</th>
                </tr>
                </thead>

                <tbody>

                @foreach($row->detail as $item)
                    <?php
                    //发货,最大可申发数量
                    $maxNum = $item->order_num - $item->apply_num ?? 0;

                    //获取(FBA)发货站点下的账号以及sku可用库存
                    $FBAareaInventoryList = App\Models\SalesReport\FBAInventory::getFBAInventory([$row->area_id], $item->psku_id, $maxNum);

                    //获取发货站点下对应的海外仓库id
                    $wareHouseids = App\Models\OverSeasBa\Warehouse::getIdsByAreaId([$row->area_id]);
                    //获取(海外仓)发货站点下的的sku库存
                    $wareHouseInventoryList = App\Models\OverSeasBa\Warehouse::getWarehouseAeraInventory($row->plat_id, $wareHouseids, $item->psku_id, $maxNum);
                    //获取(国内仓)发货站点下的库存
                    $cnAeraInventory = App\Models\Inventory\InventoryCn::getCnAeraInventory($item->psku_id, $maxNum);

                    //初始key
                    $key = 0;
                    ?>

                    <tr>
                        <td>
                            @if($item->status < App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_YES)
                                <input type="checkbox"
                                       class="grid-row-checkbox"
                                       data-plat-id="{{ $row->plat_id }}"
                                       data-id="{{ $item->psku_id . $row->order_no }}"
                                       id="{{ 'checkbox-' . $item->psku_id . $row->order_no }}" />
                            @endif
                        </td>

                        <!--start 根据sku展开发货方式模板-->
                        <td>
                            {{--<div>--}}
                            @if($item->status < App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_YES)
                                <span class="grid-expand-grid-row" style="float: left; width: 80%;"
                                      data-inserted="0"
                                      data-name="{{ 'sku-psku_code-'.$item->psku_id . $row->order_no }}"
                                      data-toggle="collapse"
                                      data-target="#grid-collapse-{{ 'sku-psku_code-'.$item->psku_id . $row->order_no }}">
                                <a href="javascript:void(0)" data-sku-id="{{ $item->psku_id }}" title="点我,展开发货方式">
                                    <i class="fa fa-angle-double-down"></i>&nbsp;&nbsp;{{ $item->sku->psku_code ?? '' }}
                                </a>
                            </span>
                            @else
                                {{ $item->sku->psku_code ?? '' }}
                            @endif

                            <!--删除sku-->
                            @if($row->detail->count() > 1 && in_array($item->status, [App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO]))
                                @if($item->status == App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO)
                                    <span style="float: right;margin-top: -6px;width: 20%;">
                                        <a href="javascript:void(0);" title="删除产品" class="btn btn-box-tool grid-detail-delete" data-id="{{ $item->id }}"><i class="fa fa-remove"></i></a>
                                    </span>
                                @endif
                            @endif

                            <template class="grid-expand-{{ 'sku-psku_code-'.$item->psku_id . $row->order_no }}">
                            <tr style="background-color: #ecf0f5;">
                                <td colspan='100%' style='padding:0 !important; border:0;'>
                                    <div id="grid-collapse-{{ 'sku-psku_code-'.$item->psku_id . $row->order_no }}" class="collapse">
                                        <div style="padding: 10px 10px 0 10px;" class="html">
                                        @if($areaName == 'PUBLIC' || $areaName == 'OUT')
                                            <!-- 国内仓 -->
                                                @if((!empty($cnAeraInventory)) && in_array($item->status, [App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO, App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_PART]))
                                                    <table class="table">
                                                        <thead>
                                                        <tr style="text-align: center;">
                                                            <th width="10%">国内发货 &nbsp;
                                                                <i class="fa fa-question-circle" style="color: #3c8dbc" title="国内库存扣减的优先级：OUT > PUBLIC > 其他站点"></i>
                                                            </th>
                                                            <th width="10%">OUT库存</th>
                                                            <th width="10%">PUBLIC库存</th>
                                                            <th width="20%">其它站点库存（<a target="_blank" href="/xqc/inventory/area-cn?sku={{ $item->sku->psku_code ?? '' }}">查看 <i class="fa fa-search" style="font-size: small;"></i></a>）</th>
                                                            <th width="10%">可申发数量</th>
                                                            <th width="10%"> </th>
                                                            <th width="20%">备注</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>
                                                        <?php $key++; $k3 = 0; $sum1 = $cnAeraInventory['OUT'] + $cnAeraInventory['PUBLIC']; ?>
                                                            <tr>
                                                                <td>
                                                                    <input type="radio" name="{{ $item->psku_id . $row->order_no }}"
                                                                           class="grid-row-radio"
                                                                           id="{{ 'radio-'. $key .'-'. $k3 .$item->psku_id . $row->order_no . $deliveryThree}}"
                                                                           data-parent-id="{{ $item->psku_id . $row->order_no }}"
                                                                           data-id="{{ $item->psku_id . $row->order_no . $deliveryThree . $k3 }}"
                                                                           data-order-no="{{ $row->order_no }}"
                                                                           data-order-detail-id="{{ $item->id }}"
                                                                           data-psku-id="{{ $item->psku_id }}"
                                                                           data-delivery-type="{{ $deliveryThree }}">
                                                                </td>
                                                                <td > {{ $cnAeraInventory['OUT'] }} </td>
                                                                <td > {{ $cnAeraInventory['PUBLIC'] }} </td>
                                                                <td> {{ $cnAeraInventory['OTHER'] }} </td>
                                                                <td>
                                                                    <input id="this_apply_num_{{ $item->psku_id . $row->order_no . $deliveryThree . $k3 }}"
                                                                           class="form-control this_apply_num_" style="margin: auto;width: 100px; text-align: right;"
                                                                           name=""
                                                                           data-max="{{ $maxNum }}"
                                                                           value="{{ $maxNum }}" >
                                                                </td>
                                                                <td>  </td>
                                                                <td>
                                                                    <input type="text" id="this_apply_remarks_{{ $item->psku_id . $row->order_no . $deliveryThree . $k3 }}"
                                                                           class="form-control this_apply_remarks_" name="{{ $row->remarks  }}"
                                                                           value="{{ $row->remarks  }}">
                                                                </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                @else
                                                @endif
                                            @else
                                            <!-- FBA仓 -->
                                                @if($FBAareaInventoryList->isNotEmpty() && in_array($item->status, [App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO, App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_PART]))
                                                    <table class="table">
                                                        <thead>
                                                        <tr style="text-align: center;">
                                                            <th width="10%">FBA(亚马逊)</th>
                                                            <th width="10%">发货站点</th>
                                                            <th width="10%">平台SKU</th>
                                                            <th width="10%">库存</th>
                                                            <th width="20%">FBA账号</th>
                                                            <th width="10%">可申发数量</th>
                                                            <th width="20%">备注</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>

                                                        @foreach($FBAareaInventoryList as $k1 => $v1)
                                                            <?php $key++; ?>
                                                            <tr>
                                                                <td>
                                                                    <input type="radio" name="{{ $item->psku_id . $row->order_no }}"
                                                                            class="grid-row-radio"
                                                                            id="{{ 'radio-'. $key .'-'. $k1 .$item->psku_id . $row->order_no . $deliveryOne }}"
                                                                            data-parent-id="{{ $item->psku_id . $row->order_no }}"
                                                                            data-id="{{ $item->psku_id . $row->order_no . $deliveryOne . $k1 }}"
                                                                            data-order-no="{{ $row->order_no }}"
                                                                            data-order-detail-id="{{ $item->id }}"
                                                                            data-psku-id="{{ $item->psku_id }}"
                                                                            data-delivery-type="{{ $deliveryOne }}"
                                                                            data-seller-sku="{{ $v1->seller_sku }}"
                                                                            data-account-id="{{ $v1->account_id ?? 0 }}">
                                                                </td>
                                                                <td> {{ $v1->area->area }} </td>
                                                                <td> {{ $v1->seller_sku }} </td>
                                                                <td> {{ $v1->num ?? 0 }} </td>
                                                                <td> {{ \App\Models\Basics\SysPlatAccount::getAccountById($v1->account_id ?? 0) }} </td>
                                                                <td>
                                                                    <input id="this_apply_num_{{ $item->psku_id . $row->order_no . $deliveryOne . $k1 }}"
                                                                           class="form-control this_apply_num_" style="margin: auto; width: 100px; text-align: right;" name=""
                                                                           data-max="{{ $maxNum }}"
                                                                           value="{{ $maxNum }}" >
                                                                </td>
                                                                <td>
                                                                    <input type="text" id="this_apply_remarks_{{ $item->psku_id . $row->order_no . $deliveryOne . $k1 }}"
                                                                           class="form-control this_apply_remarks_" name="{{ $row->remarks }}"
                                                                           value="{{ $row->remarks }}">
                                                                </td>
                                                            </tr>
                                                        @endforeach
                                                        </tbody>
                                                    </table>
                                                @else
                                                @endif
                                            <!-- 海外仓 -->
                                                @if($wareHouseInventoryList->isNotEmpty() && in_array($item->status, [App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO, App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_PART]))
                                                    <?php $key++; ?>
                                                    <table class="table">
                                                        <thead>
                                                        <tr style="text-align: center;">
                                                            <th width="10%">海外仓发货</th>
                                                            <th width="10%">站点</th>
                                                            <th width="10%">库存</th>
                                                            <th width="20%">账号</th>
                                                            <th width="10%">仓库</th>
                                                            <th width="10%">可申发数量</th>
                                                            <th width="20%">备注</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>
                                                        @foreach($wareHouseInventoryList as $k2 => $v2)
                                                            <tr>
                                                                <td>
                                                                    <input type="radio" name="{{ $item->psku_id . $row->order_no }}"
                                                                            class="grid-row-radio"
                                                                            id="{{ 'radio-'. $key .'-'. $k2 .$item->psku_id . $row->order_no . $deliveryTwo }}"
                                                                            data-parent-id="{{ $item->psku_id . $row->order_no }}"
                                                                            data-id="{{ $item->psku_id . $row->order_no . $deliveryTwo . $k2 }}"
                                                                            data-order-no="{{ $row->order_no }}"
                                                                            data-order-detail-id="{{ $item->id }}"
                                                                            data-psku-id="{{ $item->psku_id }}"
                                                                            data-delivery-type="{{ $deliveryTwo }}"
                                                                            data-warehouse-id="{{ $v2->wareHouse->id ?? 0 }}"
                                                                            data-account-id="{{ $v2->account_id ?? 0 }}">
                                                                </td>
                                                                <td > {{ $areaName }} </td>
                                                                <td > {{ $v2->num ?? 0 }} </td>
                                                                <td > {{ \App\Models\Basics\SysPlatAccount::getAccountById($v2->account_id ?? 0) }} </td>
                                                                <td > {{ $v2->wareHouse->w_code }} </td>

                                                                <td>
                                                                    <input id="this_apply_num_{{ $item->psku_id . $row->order_no . $deliveryTwo . $k2 }}"
                                                                           class="form-control this_apply_num_" style="margin: auto;width: 100px; text-align: right;"
                                                                           name=""
                                                                           data-max="{{ $maxNum }}"
                                                                           value="{{ $maxNum }}" >
                                                                </td>
                                                                <td>
                                                                    <input type="text" id="this_apply_remarks_{{ $item->psku_id . $row->order_no . $deliveryTwo . $k2 }}"
                                                                           class="form-control this_apply_remarks_" name="{{ $row->remarks  }}"
                                                                           value="{{ $row->remarks  }}">
                                                                </td>
                                                            </tr>
                                                        @endforeach
                                                        </tbody>
                                                    </table>
                                                @else
                                                @endif
                                            <!-- 国内仓 -->
                                                @if((!empty($cnAeraInventory)) && in_array($item->status, [App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO, App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_PART]))
                                                    <table class="table">
                                                        <thead>
                                                        <tr style="text-align: center;">
                                                            <th width="10%">国内发货 &nbsp;
                                                                <i class="fa fa-question-circle" style="color: #3c8dbc" title="国内库存扣减的优先级：OUT > PUBLIC > 其他站点"></i>
                                                            </th>
                                                            <th width="10%">OUT库存</th>
                                                            <th width="10%">PUBLIC库存</th>
                                                            <th width="20%">其它站点库存（<a target="_blank" href="/xqc/inventory/area-cn?sku={{ $item->sku->psku_code ?? '' }}">查看 <i class="fa fa-search" style="font-size: small;"></i></a>）</th>
                                                            <th width="10%">可申发数量</th>
                                                            <th width="10%"> </th>
                                                            <th width="20%">备注</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>
                                                        <?php $key++; $k3 = 0; $sum1 = $cnAeraInventory['OUT'] + $cnAeraInventory['PUBLIC']; ?>
                                                        <tr>
                                                            <td>
                                                                <input type="radio" name="{{ $item->psku_id . $row->order_no }}"
                                                                       class="grid-row-radio"
                                                                       id="{{ 'radio-'. $key .'-'. $k3 .$item->psku_id . $row->order_no . $deliveryThree}}"
                                                                       data-parent-id="{{ $item->psku_id . $row->order_no }}"
                                                                       data-id="{{ $item->psku_id . $row->order_no . $deliveryThree . $k3 }}"
                                                                       data-order-no="{{ $row->order_no }}"
                                                                       data-order-detail-id="{{ $item->id }}"
                                                                       data-psku-id="{{ $item->psku_id }}"
                                                                       data-delivery-type="{{ $deliveryThree }}">
                                                            </td>
                                                            <td> {{ $cnAeraInventory['OUT'] }} </td>
                                                            <td> {{ $cnAeraInventory['PUBLIC'] }} </td>
                                                            <td> {{ $cnAeraInventory['OTHER'] }} </td>
                                                            <td>
                                                                <input id="this_apply_num_{{ $item->psku_id . $row->order_no . $deliveryThree . $k3 }}"
                                                                       class="form-control this_apply_num_" style="margin: auto;width: 100px; text-align: right;"
                                                                       name=""
                                                                       data-max="{{ $maxNum }}"
                                                                       value="{{ $maxNum }}" >
                                                            </td>
                                                            <td>  </td>
                                                            <td>
                                                                <input type="text" id="this_apply_remarks_{{ $item->psku_id . $row->order_no . $deliveryThree . $k3 }}"
                                                                       class="form-control this_apply_remarks_" name="{{ $row->remarks  }}"
                                                                       value="{{ $row->remarks  }}">
                                                            </td>
                                                        </tr>
                                                        </tbody>
                                                    </table>
                                                @else
                                                @endif
                                            @endif
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <script type="text/javascript">
                                $(function () {
                                    //选中单选时,勾选上级复选框
                                    $('.grid-row-radio').iCheck({radioClass:'iradio_minimal-blue'}).on('ifChanged', function () {

                                        let parentId = $(this).data('parent-id');
                                        let  checkboxObj = $('#checkbox-' + parentId);
                                        if (this.checked) {
                                            if(!checkboxObj.checked){
                                                checkboxObj.iCheck('check');
                                            }
                                        }
                                    });
                                    //验证数量(格式)
                                    $(".this_apply_num_").inputmask("integer",
                                        {
                                            onKeyValidation: function () {
                                                if($(this).val() > $(this).data('max') || $(this).val()<= 0){
                                                    $(this).val($(this).data('max'));
                                                }
                                            }
                                        }
                                    );
                                });
                            </script>
                            </template>
                        </td>
                        <!--end 列展开结束-->

                        <td>{{ $item->sku->psku_cn ?? '' }}</td>
                        @if($item->status == App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO)
                            <td>
                                <a class="grid-editable-detail-order_num" href="#"
                                   data-type="text"
                                   data-pk="{{ $item->id }}"
                                   data-url="{{ '/xqc/customer-delivery/delivery-demand/'.$item->id }}"
                                   data-value="{{ $item->order_num  ?? 0  }}"> {{ $item->order_num  ?? 0 }}
                                </a>
                            </td>
                        @else
                            <td>{{ $item->order_num ?? 0 }}</td>
                        @endif
                        <td>{{ $item->apply_num ?? 0 }}</td>
                        <td>
                            @if($item->status < App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_YES)
                                <span style="color: #00a65a">
                                    {{ \App\Models\CustomerDelivery\CustomerOrderDetails::$_status[$item->status] }}
                                </span>
                            @elseif($item->status == App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_CANCEL)
                                <span style="color: red">
                                    {{ \App\Models\CustomerDelivery\CustomerOrderDetails::$_status[$item->status] }}
                                </span>
                            @else
                                {{ \App\Models\CustomerDelivery\CustomerOrderDetails::$_status[$item->status] }}
                            @endif
                        </td>
                        <td>{{ $row->remarks ?? '' }}</td>
                        <td>
                            @if($item->status == App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_CANCEL)
                                <a href="javascript:void(0);" data-id="{{ $item->id }}" class="btn btn-xs btn-default grid-detail-enable">启用</a>
                            @elseif($item->status == App\Models\CustomerDelivery\CustomerOrderDetails::ORDER_DELIVERY_NO)
                                <a href="javascript:void(0);" data-id="{{ $item->id }}" class="btn btn-xs btn-default grid-detail-cancel">取消</a>
                            @else
                                <a href="javascript:void(0);" class="btn btn-xs btn-default" style="outline:none;text-decoration:none;color:#bfbfbf; cursor:not-allowed;">取消</a>
                            @endif
                        </td>
                </tr>
        @endforeach

        </tbody>
        </table>
    </div>
    </div>
@endforeach

<div class="modal fade" id="listDetailModal">
    <div class="modal-dialog" style="width: 50%;">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="listModal" tabindex="-1" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog" style="width: 60%;">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script language="JavaScript" type="text/javascript">
    $(function () {
        //列展开 (默认添加模板数据)
        $('.grid-expand-grid-row').each(function() {
            let name = $(this).data('name');
            let row = $(this).closest('tr');
            row.after($('template.grid-expand-'+name).html());
        });

        //列展开
        $('.grid-expand-grid-row').on('click', function () {
            if ($(this).data('inserted') == '0') {
                $(this).data('inserted', 1);
            }
            $("i", this).toggleClass("fa-angle-double-down fa-angle-double-up");
        });

        //单行选择框
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {

            let id = $(this).data('id');
            let platId = $(this).data('plat-id');

            if (this.checked) {
                $.admin.grid.select(id);
                $(this).closest('tr').css('background-color', '#ffffd5');

                if (platId == 3) {
                    //rakuten平台发货优先级 (海外仓 > FBA > 国内)
                    //复选选中时，验证单选 (默认选择一种发货方式)
                    if(!$("input[name='" + id + "']:checked").val()){
                        //优先海外仓
                        if ($('#radio-2-0' + id + {{ $deliveryTwo }} ).length > 0) {
                            $('#radio-2-0' + id + {{ $deliveryTwo }} ).iCheck('check');
                        }else{
                            //次先FBA
                            if($('#radio-1-0' + id + {{ $deliveryOne }} ).length > 0){
                                $('#radio-1-0' + id + {{ $deliveryOne }} ).iCheck('check');
                            }else{
                                //最后国内仓
                                if ( $('#radio-1-0' + id + {{ $deliveryThree }} ).length > 0) {
                                    $('#radio-1-0' + id + {{ $deliveryThree }} ).iCheck('check');
                                }
                            }
                        }
                    }
                }else {
                    //其他平台发货优先级 (FBA > 海外仓 > 国内)
                    //复选选中时，验证单选 (默认选择一种发货方式)
                    if(!$("input[name='" + id + "']:checked").val()){
                        //优先fba
                        if($('#radio-1-0' + id + {{ $deliveryOne }} ).length > 0){
                            $('#radio-1-0' + id + {{ $deliveryOne }} ).iCheck('check');
                        }else{
                            //次先海外仓
                            if ($('#radio-1-0' + id + {{ $deliveryTwo }} ).length > 0) {
                                $('#radio-1-0' + id + {{ $deliveryTwo }} ).iCheck('check');
                            }else{
                                //最后国内仓
                                if ( $('#radio-1-0' + id + {{ $deliveryThree }} ).length > 0) {
                                    $('#radio-1-0' + id + {{ $deliveryThree }} ).iCheck('check');
                                }
                            }
                        }
                    }
                }

            } else {
                $.admin.grid.unselect(id);
                $(this).closest('tr').css('background-color', '');

                $("input[name='" + id + "']:checked").each(function() {
                    $(this).iCheck('uncheck');
                });
            }

        }).on('ifClicked', function () {
            let id = $(this).data('id');

            if (this.checked) {
                $.admin.grid.unselect(id);
            }else {
                $.admin.grid.select(id);
            }
        });

        //全选
        $('.grid-select-all').iCheck({checkboxClass:'icheckbox_minimal-blue'});
        $('.grid-select-all').on('ifChanged', function(event) {
            if (this.checked) {
                $('.grid-row-checkbox').iCheck('check');
            } else {
                $('.grid-row-checkbox').iCheck('uncheck');
            }
        }).on('ifClicked', function () {
            if (this.checked) {
                $.admin.grid.selects = {};
            } else {
                $('.grid-row-checkbox').each(function () {
                    var id = $(this).data('id');
                    $.admin.grid.select(id);
                });
            }
        });


        let _ajaxConfirm = function(action,param,resolve){
            $.ajax({
                method: 'post',
                url: '/xqc/customer-delivery/delivery-demand-ajax',
                data: {
                    _token: "{{ csrf_token() }}",
                    action: action,
                    param: param
                },
                success: function (data) {
                    resolve(data);
                }
            });
        };

        //添加产品
        $('.list-detail-modal').on('click', function(e) {
            e.preventDefault();
            let id = $(this).data('id');
            let action = $(this).data('action');
            $("#listDetailModal").modal({
                remote : '/xqc/customer-delivery/delivery-demand-modal?param=' + id + '&action=' + action,
            });
        });
        $("#listDetailModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        //查看
        $('.list-modal').on('click', function(e) {
            e.preventDefault();
            let id = $(this).data('id');
            let action = $(this).data('action');
            $("#listModal").modal({
                remote : '/xqc/customer-delivery/delivery-demand-modal?param=' + id + '&action=' + action,
            });
        });
        $("#listModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        //删除订单
        $('.grid-row-delete').on('click', function () {
            let id = $(this).data('id');
            swal({
                title: "确定删除？",
                text : "确定要删除此订单吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('delOutOrder',id,resolve);
                    });
                }
            }).then(function(result) {
                let data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success(data.message);
                        $.pjax.reload('#pjax-container');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //删除商品项
        $('.grid-detail-delete').on('click', function () {
            let id = $(this).data('id');
            swal({
                title: "确定删除？",
                text : "确定要删除此产品吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('delOutOrderSku',id,resolve);
                    });
                }
            }).then(function(result) {
                let data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        $.pjax.reload('#pjax-container');
                        toastr.success(data.message);
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //取消商品项
        $('.grid-detail-cancel').unbind('click').click(function(e) {
            e.preventDefault();
            let id = $(this).data('id');
            swal({
                title: "确定取消？",
                text : "确定要取消此商品吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('cancelOutOrderItem',id,resolve);
                    });
                }
            }).then(function(result) {
                let data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        $.pjax.reload('#pjax-container');
                        toastr.success(data.message);
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //启用商品项
        $('.grid-detail-enable').unbind('click').click(function(e) {
            e.preventDefault();
            let id = $(this).data('id');
            swal({
                title: "确定启用？",
                text : "确定要启用此商品吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('enableOutOrderItem',id,resolve);
                    });
                }
            }).then(function(result) {
                let data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        $.pjax.reload('#pjax-container');
                        toastr.success(data.message);
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //更新数量
        let _editable = function (name,showbuttons = false,mode = "inline") {
            $('.grid-editable-'+name).editable({
                "emptytext":"<i class=\"fa fa-pencil\"><\/i>",
                "showbuttons":showbuttons,
                "mode":mode,
                "name":name,
                success: function(response, newValue) {
                    if (typeof response === 'object') {
                        if (response.status) {
                            toastr.success(response.message);
                        } else {
                            swal(response.message, '', 'error');
                        }
                    }
                }
            });
        };
        _editable('detail-order_num');

    });
</script>
